package com.ubao.activity;


import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;

import com.ubao.R;
import com.ubao.activity.MyApp.GoBack;
import com.ubao.dialog.ExitDialog;
import com.ubao.global.GoBackable;
import com.ubao.ui.SlidingMenuView;
import com.ubao.util.log.Logger;
import com.youxilua.waterfallapp.WaterFallActivity;

public class MainActivity extends ActivityGroup implements GoBackable{
	private final static String TAG = "ubao";
	SlidingMenuView slidingMenuView;
	
	ViewGroup tabcontent;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        slidingMenuView = (SlidingMenuView) findViewById(R.id.sliding_menu_view);
        MyApp.slidingMenuView = slidingMenuView;
        tabcontent = (ViewGroup) slidingMenuView.findViewById(R.id.sliding_body);
        new Handler(){public void handleMessage(android.os.Message msg) {showDefaultTab();};}.sendEmptyMessageDelayed(0, 500);
    }
    
    public void showMenu(View view){
    	slidingMenuView.scrollLeft();
    }
    
    public void myProducts(View view){
    	Logger.d("myFriend");
    	Intent i = new Intent(this,MyProductActivity.class);
    	View v = getLocalActivityManager().startActivity(MyProductActivity.class.getName(), i).getDecorView();
		tabcontent.removeAllViews();
		tabcontent.addView(v);
		slidingMenuView.scrollRight();
    }
    
    public void myWants(View view){
    	Logger.d("myWants");
    	Intent i = new Intent(this,MyWantsActivity.class);
    	View v = getLocalActivityManager().startActivity(MyWantsActivity.class.getName(), i).getDecorView();
		tabcontent.removeAllViews();
		tabcontent.addView(v);
		slidingMenuView.scrollRight();
    }
    
    public void myFollers(View view){
    	Logger.d("myFollers");
//    	Intent i = new Intent(this,TestActivity2.class);
//    	View v = getLocalActivityManager().startActivity(TestActivity2.class.getName(), i).getDecorView();
//		tabcontent.removeAllViews();
//		tabcontent.addView(v);
    }
    
    public void myFollowing(View view){
    	Logger.d("myFollwing");
    	Intent i = new Intent(this,MaiFriend.class);
    	View v = getLocalActivityManager().startActivity(MaiFriend.class.getName(), i).getDecorView();
		tabcontent.removeAllViews();
		tabcontent.addView(v);
		slidingMenuView.scrollRight();
    }
    
    public void myProfile(View view){
    	Logger.d("myProfile");
    	setGoBack();
    	Intent i = new Intent(this,LoginActivity.class);
    	View v = getLocalActivityManager().startActivity(LoginActivity.class.getName(), i).getDecorView();
		tabcontent.removeAllViews();
		tabcontent.addView(v);
		slidingMenuView.scrollRight();
    }
    
    public void settings(View view){
    	Logger.d("settings");
//    	Intent i = new Intent(this,TestActivity2.class);
//    	View v = getLocalActivityManager().startActivity(TestActivity2.class.getName(), i).getDecorView();
//		tabcontent.removeAllViews();
//		tabcontent.addView(v);
    }
    
    public void feedBack(View view){
    	Logger.d("feedback");
//    	Intent i = new Intent(this,TestActivity2.class);
//    	View v = getLocalActivityManager().startActivity(TestActivity2.class.getName(), i).getDecorView();
//		tabcontent.removeAllViews();
//		tabcontent.addView(v);
    }
    
    void showDefaultTab(){
    	Intent i = new Intent(this,MyProductActivity.class);
    	View v = getLocalActivityManager().startActivity(MyProductActivity.class.getName(), i).getDecorView();
		tabcontent.removeAllViews();
		tabcontent.addView(v);
    }


    @Override
	public void setGoBack() {
		Bundle bundle = new Bundle();
		bundle.putString("back2", getClass().getName());
		GoBack.goBackStack.add(bundle);
	}
    
    
    @Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new ExitDialog( MyApp.getMyApp(), this).show();
			return true;
		}
		// TODO Auto-generated method stub
		return super.onKeyDown(keyCode, event);
	}
}
